// 加入购物车接口

import type { CartItem } from "@/types/cart"
import { http } from "@/utils/http"

// 加入购物车接口(参数: 商品id, 商品数量)
export const postMemberCartAPI = (data: { skuId: string, count: number }) => {
    return http({
        method: 'POST',
        url: '/member/cart',
        data
    })
}

// 获取购物车列表接口
export const getMemberCartAPI = () => {
    return http<CartItem[]>({
        method: 'GET',
        url: '/member/cart'
    })
}

// 删除/清空购物车单品接口(data为请求参数, ids为SKUID集合)
export const deleteMemberCartAPI = (data: { ids: string[]} ) => {
    return http({
        method: 'DELETE',
        url: '/member/cart',
        data
    })
}

// 修改购物车单品数量/选中状态接口(参数: 选中状态, 商品数量)
export const putMemberCartBySkuIdAPI = (skuId: string, data: {selected?: boolean, count?: number}) => {
    return http({
        method: 'PUT',
        url: `/member/cart/${skuId}`,
        data
    })
}

// 修改购物车全选/取消全选接口(参数: 是否选中)
export const putMemberCartSelectedAPI = (data: {selected: boolean}) => {
    return http ({
        method: 'PUT',
        url: '/member/cart/selected',
        data
    })
}